//
//  CarsTableViewCell.m
//  10_HomeWork
//
//  Created by dllo on 16/7/27.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "CarsTableViewCell.h"
#import "UIView+Frame.h"
#import "ModelOfCar.h"
#import "UIImageView+DownloadImage.h"
@interface CarsTableViewCell ()

@end

@implementation CarsTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.image_view = [[UIImageView alloc] init];
        self.title = [[UILabel alloc] init];
        [self.contentView addSubview:_image_view];
        [self.contentView addSubview:_title];
    }
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat imageTopMargin = 10;
    CGFloat imageLeftMargin = 5;
    CGFloat titleLeftimage = 5;
    CGFloat imageWidth = self.dm_width * 1 / 4;
    CGFloat imageHeight = self.dm_height * 3 / 4;
    _image_view.frame = CGRectMake(imageLeftMargin, imageTopMargin, imageWidth, imageHeight);
    _title.frame = CGRectMake(imageLeftMargin + imageWidth + titleLeftimage, self.contentView.dm_height / 2 - 5, self.dm_width * 3 / 4 - titleLeftimage, 20);
}
- (void)setModel:(ModelOfCar *)model {
    _model = model;
    _title.text = _model.title;
    [_image_view asyncDownloadImageWithURL:_model.imageURL completionHandler:^(NSData *data, UIImage *image) {
    
        
    }];
}

@end
